#include <iostream>
using namespace std;

class A
{
public:
	virtual void func(int val = 1){
        std::cout << "A->" << val << std::endl;
    }
};

class B : public A
{
public:
	void func(int val = 0){
        std::cout << "B->" << val << std::endl;
    }

	virtual void test(){
        func();
    }
};

int main(int argc, char* argv[])
{
	B*p = new B;
	p->test();
	return 0;
}

/*
class A
{
public:
    virtual void func(int val = 1){
        std::cout << "A->" << val << std::endl;
    }

    virtual void test(){
        func();
    }
};

class B : public A
{
public:
    void func(int val = 0){
        std::cout << "B->" << val << std::endl;
    }
};

int main(int argc, char* argv[])
{
    B* p = new B;
    p->test();
    return 0;
}
*/

/*
class A
{
public:
    virtual void func(int val = 1){
        std::cout << "A->" << val << std::endl;
    }

    virtual void test(){
        func();
    }
};

class B : public A
{
public:
    void func(int val = 0){
        std::cout << "B->" << val << std::endl;
    }
};

int main(int argc, char* argv[])
{
    A* p = new B;
    p->test();
    return 0;
}
*/

/*
class Person{
public:
    virtual void BuyTicket(){
        cout << "complete" << endl;
    }

    virtual ~Person(){
        cout << "~Person()" << endl;
    }
};

class Student:public Person{
public:
    void BuyTicket() override{
        cout << "half" << endl;
    }

    ~Student() override{
        cout << "~Student" << endl;
    }
};

void Func(Person* p){
    p->BuyTicket();
    delete p;
}

void test1(){
    Func(new Person);
    Func(new Student);
}

void Func(Person& p)
{
	// 1、不满足多态 -- 看调用者的类型，调用这个类型的成员函数
	// 2、满足多态   -- 看指向的对象的类型，调用这个类型的成员函数
 	p.BuyTicket();
}

void test2()
{
	Person ps;
	Student st;

	Func(ps);
	Func(st);
}

int main(){
    test2();
    return 0;
}
*/

//抽象类(包含纯虚函数):不能实例化出对象
//派生类继承后也不能实例化出对象(除非重写纯虚函数)

/*
class Car{
public:
    virtual void Drive() = 0;
};

class BMW:public Car{
    void Drive(){
        cout << "BMW" << endl;
    }
};

int main(){
    //Car car;
    BMW bmwCar;
    return 0;
}
*/

//多态原理

/*
class Base{
public:
    virtual void Func1(){
        cout << "Func1()" << endl;
    }
private:
    int _b = 1;
    char _ch;
};

int main(){
    cout << sizeof(Base) << endl;
    Base bb;
    return 0;
}
*/

/*
class Person {
public:
	virtual void BuyTicket() { cout << "complete" << endl; }
	virtual void Func() { cout << "complete" << endl; }

	int _a = 0;

};

class Student : public Person {
public:
	virtual void BuyTicket() { cout << "half" << endl; }

	int _b = 1;
};

void Func(Person& p)
{
	p.BuyTicket();
}

int main()
{
	Person mike;
	Func(mike);

	Student johnson;
	Func(johnson);
	//mike = johnson;

	return 0;
}
*/

/*
class Base{
public:
    virtual void Func1(){
        cout << "Base::Func1()" << endl;
    }

    virtual void Func2(){
        cout << "Base::Func2()" << endl;
    }

    void Func3(){
        cout << "Base::Func3()" << endl;
    }

private:
    int _b = 1;
};

class Derive : public Base{
public:
    virtual void Func1(){
        cout << "Derive::Func1()" << endl;
    }
private:
    int _d = 2;
};

int main(){
    Base b1;
    Base b2;
    Base b3;

    Derive d;

    b1.Func1();
    b1.Func3();
    return 0;
}
*/
